package com.silence.springboot;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

import java.util.UUID;

/**
 * @Author silence
 * @Date 2024-09-05 00:20
 * @Email 792245022@qq.com
 * @Version 1.0
 * @Description
 */
@Mapper(imports = {UUID.class}, componentModel = MappingConstants.ComponentModel.SPRING)
public interface MapStructFactory {

    /**
     * Person to PersonVo
     *
     * @param person Person
     * @return PersonVo
     */
    @Mapping(target = "phone", source = "anotherPojo.phone")
    @Mapping(target = "email", source = "anotherPojo.email")
    @Mapping(target = "uuid", expression = "java(UUID.randomUUID().toString())")
    @Mapping(target = "phoneAndEmail", expression = "java(person.getAnotherPojo().getPhone() + \" - \" + person.getAnotherPojo().getEmail())")
    PersonVo person2PersonVo(Person person);
}
